package swu.cx.androidmvvm

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val viewModel = ViewModelProvider(this).get(MyViewModel::class.java)
        viewModel.content.observe(this){
            showText.text = it
        }
        viewModel.name.observe(this){
            //具体操作
        }
        convert.setOnClickListener {
            viewModel.content.value = "我爱Android"
        }
    }
}